package com.hyst.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.RecommendMsg;
import com.hyst.domain.Student;
import com.hyst.repository.RecommendMsgMapper;
import com.hyst.service.RecommendMsgService;

/**
 * @Description:controller
 * @author：dy 
 *@Date：2018年09月26日
 */
@RestController
@RequestMapping("recommendMsgs")
@CrossOrigin(maxAge = 3600, origins = "*")
public class RecommendMsgController {
	@Autowired
	private RecommendMsgService recommendMsgService;

	@Autowired
	private RecommendMsgMapper recommendMsgMapper;
	
	@GetMapping
	public ResultPage<RecommendMsg> list(RecommendMsg recommendMsg) {
		return ResultPage.success(recommendMsgService.list(recommendMsg));
	}


	@PostMapping
	public ResultBean<RecommendMsg> creat(final RecommendMsg recommendMsg) {
		return ResultBean.success(recommendMsgService.insert(recommendMsg));
	}

	/**
	 * @Description: 根据主键查询
	 * @param uniqueId
	 * @return ResultBean<RecommendMsg>
	 */
	@GetMapping("{uniqueId}")
	public ResultBean<RecommendMsg> getByPriKey(@PathVariable("uniqueId") final String uniqueId) {
		return ResultBean.success(recommendMsgService.getByPriKey(uniqueId));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param recommendMsg
	 * @return ResultBean<RecommendMsg>
	 */
	@PatchMapping("{uniqueId}")
	public ResultBean<RecommendMsg> update(final RecommendMsg recommendMsg) {
		return ResultBean.success(recommendMsgService.update(recommendMsg));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param recommendMsg
	 * @return ResultBean<RecommendMsg>
	 */
	//@PutMapping("{uniqueId}")
	@PostMapping("{uniqueId}")
	public ResultBean<RecommendMsg> updatePatch(@PathVariable("uniqueId") final String uniqueId,
			final RecommendMsg recommendMsg) {
		return ResultBean.success(recommendMsgService.updateSelective(recommendMsg));
	}

	/**
	 * @Description: 根据主键删除
	 * @param uniqueId
	 * @return ResultBean<RecommendMsg>
	 */
	@DeleteMapping("{uniqueId}")
	public ResultBean<RecommendMsg> delete(@PathVariable("uniqueId") final String uniqueId) {
		return ResultBean.success(recommendMsgService.delete(uniqueId));
	}
	
	// 2018-9-27 chenbin: 保存奖励发放和备注
	@PostMapping("saveRemark")
	public ResultBean<RecommendMsg> saveRemark(@RequestParam(value = "postMsg") String postMsg) {	
		System.out.println(postMsg);
		return ResultBean.success(recommendMsgService.saveAward(postMsg));
	}
	
	// 2018-9-27 chenbin: 保存奖励核销和备注
	@PostMapping("saveSubstract")
	public ResultBean<RecommendMsg> saveSubstract(@RequestParam(value = "postMsg") String postMsg) {	
		System.out.println(postMsg);
		return ResultBean.success(recommendMsgService.saveSubstract(postMsg));
	}

	@GetMapping("/rewardWriteOff/{uid}")
	public ResultBean rewardWriteOff(@PathVariable("uid") String uid) {
		final RecommendMsg recommendMsg = new RecommendMsg();
		recommendMsg.setUniqueId(uid);
		recommendMsg.setJiangStatus("已发放");
		recommendMsgMapper.saveStatus(recommendMsg);
		return ResultBean.success(null);
	}

}
